package emergency;

import movement.Location;
import dispatch.DispatchCenter;

/**
 * A class for creating a new Fire
 */
public class Fire extends Emergency {

	/**
	 * An enumeration of size. In its current definition, the class only
	 * distinguishes between the local , house and facility size
	 */
	public enum Size {
		LOCAL, HOUSE, FACILITY
	};

	/**
	 * Variable registering the size of this Fire
	 */
	private Size size;

	/**
	 * Variable registering this Fire has chemical risks
	 */
	private boolean chemical;

	/**
	 * Variable registering the amount of people trapped in this Fire
	 */
	private int trappedPeople;

	/**
	 * Variable registering the amount of people injured in this Fire
	 */
	private int numberOfInjured;

	/**
	 * Initialize this new Fire
	 * 
	 * @param location
	 *            The location of this Fire
	 * 
	 * @param severity
	 *            The severity of this Fire
	 * 
	 * @param size
	 *            The size of this Fire
	 * 
	 * @param chemical
	 *            The occurrence of chemical products near this fire
	 * 
	 * @param trappedPeople
	 *            The occurrence whether people are trapped in this fire
	 * 
	 * 
	 * @param numberOfInjured
	 *            The amount of injured people in this fire
	 *            
	 * @param dispatchCenter
	 * 			The dispatchCenter where this fire has to be added to
	 * 
	 * @post The location of this fire is set to the given location
	 * 
	 * @post The severity of this fire is set to the given severity
	 * 
	 * @post The size of this fire is set to the given size
	 * 
	 * @post The chemical occurrence of this fire is set to the given chemical
	 *       occurrence
	 * 
	 * @post The occurrence of trapped people in the fire is set to the given
	 *       occurrence
	 * 
	 * @post The amount of injured people of this fire is set to the given
	 *       amount of people injured
	 *       
	 * @post The emergencyPolicy is set to ASAP
	 * 
	 * @post The dispatchCenter of this fire is set to the given dispatchCenter
	 * 
	 * @post This fire is added to the given dispatchcenter
	 * 
	 */
	public Fire(Location location, Severity severity,
			DispatchCenter dispatchCenter, Size size, Boolean chemical,
			int trappedPeople, int numberOfInjured) {
		super(location, severity, dispatchCenter, new EmergencyPolicyASAP());
		setSize(size);
		setChemical(chemical);
		setTrappedPeople(trappedPeople);
		setNumberOfInjured(numberOfInjured);
	}

	/**
	 * Method for checking the parameter is a valid amount ( not negative )
	 * 
	 * @param amount
	 * 			The integer you want to check for validity
	 * 
	 * @return Returns true, if valid (positive), false otherwise
	 * 		
	 */
	private boolean canHaveAsAmount(int amount) {
		return (amount >= 0);
	}

	/**
	 * Getter for getting the occurrence of chemical products in this fire
	 * 
	 * @return Returns the occurrence of chemical products in this fire
	 *         (true/false)
	 */
	public boolean getChemical() {
		return chemical;
	}

	/**
	 * Getter for getting the amount of injured people in this fire
	 * 
	 * @return Returns the amount of injured people in this fire
	 */
	public int getNumberOfInjured() {
		return numberOfInjured;
	}

	/**
	 * Getter for getting the size of this fire
	 * 
	 * @return Returns the size of this fire
	 */
	public Size getSize() {
		return size;
	}

	/**
	 * Getter for getting the amount of trapped people in this fire
	 * 
	 * @return Returns the amount of trapped people in this fire
	 */
	public int getTrappedPeople() {
		return trappedPeople;
	}

	/**
	 * Method for setting this fire it's chemical occurrence
	 * 
	 * @param chemical
	 *            The occurrence of chemical product in this fire
	 * 
	 * @post The occurrence of chemical product of this is set to the given
	 *       occurrence
	 */
	private void setChemical(boolean chemical) {
		this.chemical = chemical;
	}

	/**
	 * Method for setting this fire it's amount of injured people
	 * 
	 * @param numberOfInjured
	 *            the amount of injured people in this fire
	 * 
	 * @post the amount of injured people is set to the given amount of people
	 * 
	 * @throws IllegalArgumentException, if the given amount is not valid
	 */
	private void setNumberOfInjured(int numberOfInjured) {
		if (canHaveAsAmount(numberOfInjured))
			this.numberOfInjured = numberOfInjured;
		else
			throw new IllegalArgumentException("Amounts cannot be negative");
	}

	/**
	 * Method for setting the size of this fire
	 * 
	 * @param size
	 *            The size that needs to be set to this fire
	 * 
	 * @post The size of this fire is set to the given fire
	 * 
	 * @throws IllegalArgumentException, if given size is null
	 */
	private void setSize(Size size) {
		if(size!= null)
			this.size = size;
		else 
			throw new IllegalArgumentException("Size cannot be null");
	}

	/**
	 * Method for setting this fire it's trapped people occurrence
	 * 
	 * @param trappedPeople
	 *            The occurrence of trapped people caught in this fire
	 * 
	 * @post The amount of trapped people caught in this fire is set to the
	 *       given amount of people
	 *       
	 * @throws IllegalAccessException, if the given amount is not valid
	 */
	private void setTrappedPeople(int trappedPeople) {
		if (canHaveAsAmount(trappedPeople))
			this.trappedPeople = trappedPeople;
		else
			throw new IllegalArgumentException("Amounts cannot be negative");
	}

	/**
	 * Method for creating an description of this Fire
	 * 
	 * @return Returns the description of this Fire
	 */
	@Override
	public String toString() {
		String output = "severity is " + getSeverity().toString()+"  =  ";
		output+= getSize() + " FIRE ";
		if (chemical) {
			output += "chemical, ";
		}
		if (trappedPeople > 0) {
			output += trappedPeople + " people trapped, ";
		}
		if (numberOfInjured > 0) {
			output += numberOfInjured + " people injured ";
		}

		return output;
	}

}
